﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using BullTasDesaDal.Entities;

namespace BullTasDesaDal.Service
{
    public class ReportService
    {
        public static dsReport GetReport(int idAppraisal)
        {
            dsReport returnDataset = new dsReport();
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {

               //AppInfo
                AliasToBeanResultTransformerWithFactoryMethod<dsReport.rptAppInfoRow>
                  transformerInfo = new AliasToBeanResultTransformerWithFactoryMethod<dsReport.rptAppInfoRow>(
                      () => returnDataset.rptAppInfo.NewrptAppInfoRow());
                
                var resultAppInfo = session.GetNamedQuery("AppInfo")
                    .SetParameter("idAppraisal", idAppraisal)
                    .SetResultTransformer(transformerInfo)
                    .List<dsReport.rptAppInfoRow>();


                resultAppInfo.ToList().ForEach(returnDataset.rptAppInfo.AddrptAppInfoRow);

                //AppBettermentCamp
                AliasToBeanResultTransformerWithFactoryMethod<dsReport.rptAppBettermentCampRow>
                  transformerBettCamp = new AliasToBeanResultTransformerWithFactoryMethod<dsReport.rptAppBettermentCampRow>(
                      () => returnDataset.rptAppBettermentCamp.NewrptAppBettermentCampRow());


                var resultBettCamp = session.GetNamedQuery("AppBettermentCamp")
                    .SetParameter("idAppraisal", idAppraisal)
                    .SetResultTransformer(transformerBettCamp)
                    .List<dsReport.rptAppBettermentCampRow>();


                resultBettCamp.ToList().ForEach(returnDataset.rptAppBettermentCamp.AddrptAppBettermentCampRow);

                //AppBettermentBody
                AliasToBeanResultTransformerWithFactoryMethod<dsReport.rptAppBettermentBodyRow>
                  transformerBettBody = new AliasToBeanResultTransformerWithFactoryMethod<dsReport.rptAppBettermentBodyRow>(
                      () => returnDataset.rptAppBettermentBody.NewrptAppBettermentBodyRow());


                var resultBettBody = session.GetNamedQuery("AppBettermentBody")
                    .SetParameter("idAppraisal", idAppraisal)
                    .SetResultTransformer(transformerBettBody)
                    .List<dsReport.rptAppBettermentBodyRow>();


                resultBettBody.ToList().ForEach(returnDataset.rptAppBettermentBody.AddrptAppBettermentBodyRow);


                //AppLand
                AliasToBeanResultTransformerWithFactoryMethod<dsReport.rptAppLandRow>
                  transformerAppLand = new AliasToBeanResultTransformerWithFactoryMethod<dsReport.rptAppLandRow>(
                      () => returnDataset.rptAppLand.NewrptAppLandRow());


                var resultAppLand = session.GetNamedQuery("AppLand")
                    .SetParameter("idAppraisal", idAppraisal)
                    .SetResultTransformer(transformerAppLand)
                    .List<dsReport.rptAppLandRow>();


                resultAppLand.ToList().ForEach(returnDataset.rptAppLand.AddrptAppLandRow);


            }
            return returnDataset;
        }

    }
}
